package com.zy.mc_module.utils;

import android.view.View;

/**
 * Created on 18/10/22
 * 防止View重复点击
 */
public abstract class NoDoubleClickListener implements View.OnClickListener {
    //按钮两次点击的时间间隔不能少于230毫秒
    private static final int MIN_CLICK_DELAY_TIME = 230;
    private static long lastClickTime;

    public void onClick(View v) {
        //点击的当前时间
        long curClickTime = System.currentTimeMillis();
        if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
            // 超过点击间隔后再将lastClickTime重置为当前点击时间
            lastClickTime = curClickTime;
            onNoDoubleClick(v);
        }
    }

    public abstract void onNoDoubleClick(View v);
}
